package com.my.study.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/11/25 8:25
 **/
@Aspect
public class LogAspects {

    @Pointcut("execution(public int com.my.study.aop.MathCalculator.*(..))")
    public void point() {}

    @Before("point()")
    public void logStart(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        System.out.println(name +" logStart... 参数：(" + Arrays.asList(args) + ")");
    }

    @After("com.my.study.aop.LogAspects.point()")
    public void logEnd(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        System.out.println(name + " logEnd... 结束");
    }

    @AfterReturning(value = "point()", returning = "result")
    public void logAfterReturning(Object result) {
        System.out.println("正常返回...logAfterReturning... 结果：" + result);
    }

    @AfterThrowing(value = "point()", throwing = "ex")
    public void logAfterThrowing(Exception ex) {
        System.out.println("异常返回...logAfterThrowing... 异常：" + ex );
    }

}
